package com.coca1cole.user.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * 线程池配置示例
 */
@Configuration
public class ThreadPoolConfig {

    @Bean(name = "mailThreadPool")
    public ThreadPoolExecutor getMailThreadPool() {
        // 创建自定义的线程工厂(用于自定义线程名)
        CustomNameThreadFactory mailThreadFactory = new CustomNameThreadFactory("mail");
        // 创建线程池
        return new ThreadPoolExecutor(
                10,
                10,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingDeque<>(),
                mailThreadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy()
        );
    }

//    @Bean(name = "phoneThreadPool")
//    public ThreadPoolExecutor getPhoneThreadPool() {
//        ...
//    }
}
